package com.my.xq.repository;
import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;

import com.my.xq.domain.VoteResultQueryParam;
import com.my.xq.domain.entity.Plan_Message;
import com.sskj.core.query.annotation.DynamicQuery;
import com.sskj.core.repository.GenericRepository;

public interface PlanMessageRepository extends GenericRepository<Plan_Message, String> {
	@DynamicQuery
	Page<Plan_Message> findPage(VoteResultQueryParam vqp,Pageable pageable);
	
	@Query("SELECT r FROM Plan_Message r " + " where r.proprietorId = ?1 AND "
			+ "r.courtId=?2 and r.planId =?3 order by r.createdTime desc")
	List<Plan_Message> findPlanMessageResult(String proprietorId,String courtId,String planId);
	
	@Query("SELECT r FROM Plan_Message r " + " where r.courtId = ?1 AND "
			+ "r.proprietorId in (SELECT x.id FROM Proprietor x where x.name"
			+ " like CONCAT('%',?2,'%')) AND r.planId = ?3")
	@DynamicQuery
	Page<Plan_Message> getLeaveMessage1(String courtId,String proprietorName,
			String planId,Pageable pageable);
	
	@Query("SELECT r FROM Plan_Message r " + " where "
			+ "r.proprietorId in (SELECT x.id FROM Proprietor x where x.name"
			+ " like CONCAT('%',?1,'%')) AND r.planId = ?2")
	@DynamicQuery
	Page<Plan_Message> getLeaveMessage2(String proprietorName,
			String planId,Pageable pageable);
}
